//@author A0083782W
#include "Settings.h"

bool Settings::hasRun = false;
con_str Settings::FILENAME = "D:\\TEConfig.log";

Settings::Settings() {
	readSetting();
}

Settings& Settings::get () {
	static Settings lastSetting;

	if (hasRun == false) {
		//
		//place your "real" constructor code here
		//
		hasRun = true;
	}

	return lastSetting;
}

Settings::~Settings() {
	saveSetting();
}

void Settings::saveSetting() {
	fstream fp;
	fp.open (FILENAME, ios::out);
	fp << (pos_int) _timeDisplayFormat << endl;
	fp << (pos_int) _dateDisplayFormat << endl;
	fp << (pos_int) _timeListingOrder;
	fp.close();
}

void Settings::readSetting() {
	fstream fp;
	string fileInput;
	fp.open (FILENAME, ios::in);
	getline (fp, fileInput);
	pos_int iValue =  atoi (fileInput.c_str());
	_timeDisplayFormat = (TimeDisplayFormat) iValue;
	getline (fp, fileInput);
	iValue =  atoi (fileInput.c_str());
	_dateDisplayFormat = (DateDisplayFormat) iValue;
	getline (fp, fileInput);
	iValue =  atoi (fileInput.c_str());
	_timeListingOrder = (DisplayOrder) iValue;
	fp.close();
}

DateDisplayFormat Settings::getDateDiplayFormat() const {
	return _dateDisplayFormat;
}

void Settings::setDateDisplayFormat(DateDisplayFormat newFormat) {
	_dateDisplayFormat = newFormat;
}

TimeDisplayFormat Settings::getTimeDisplayFormat () const {
	return _timeDisplayFormat;
}

void Settings::setTimeDisplayFormat (TimeDisplayFormat newFormat) {
	_timeDisplayFormat = newFormat;
}

DisplayOrder Settings::getTimeListingOrder() const {
	return _timeListingOrder;
}
void Settings::setTimeListingOrder (DisplayOrder newOrder) {
	_timeListingOrder = newOrder;
}